//
//  PurchaseCell.m
//  MedicineBox
//
//  Created by dllo on 15/9/20.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "PurchaseCell.h"
#import "DKNightVersion.h"
#import "UIImageView+WebCache.h"

@interface PurchaseCell ()

@property (nonatomic, retain) UILabel *commentLabel;
@property (nonatomic, retain) UILabel *timeLabel;
@property (nonatomic, retain) UILabel *nameLabel;
@property (nonatomic, retain) UILabel *starView;

@end
@implementation PurchaseCell

- (void)dealloc
{
    
    [_starView release];
    [_nameLabel release];
    [_timeLabel release];
    [_commentLabel release];
    
    [super dealloc];
    
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.commentLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 30, [[UIScreen mainScreen] bounds].size.width - 10, 30)];
        self.commentLabel.font = [UIFont systemFontOfSize:12];
        _commentLabel.numberOfLines = 0;
        _commentLabel.nightTextColor = [UIColor whiteColor];
        [self.contentView addSubview:_commentLabel];
        [_commentLabel release];
    
        self.timeLabel = [[UILabel alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width / 2, _commentLabel.frame.origin.y + _commentLabel.frame.size.height, [[UIScreen mainScreen] bounds].size.width / 2 - 5, 30)];
        self.timeLabel.font = [UIFont systemFontOfSize:12];
        _timeLabel.nightTextColor = [UIColor whiteColor];
        _timeLabel.textAlignment = NSTextAlignmentRight;
        self.timeLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_timeLabel];
        [_timeLabel release];
        
        self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, _commentLabel.frame.origin.y + _commentLabel.frame.size.height + 5, 100, 30)];
        self.nameLabel.font = [UIFont systemFontOfSize:10];
        self.nameLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_nameLabel];
        _nameLabel.nightTextColor = [UIColor whiteColor];
        [_nameLabel release];
        
        self.starView = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, [[UIScreen mainScreen] bounds].size.width - 20, 30)];
        _starView.text = @"用户评级  ";
        _starView.font = [UIFont systemFontOfSize:12];
        _starView.textColor = [UIColor colorWithWhite:0.7 alpha:1];
        [self.contentView addSubview:_starView];
        [_starView release];
        
            
        for (int i = 0; i < 5; i++) {
            
            UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(50 + 20 * i, 5, 20, 20)];
            imageV.tag = 600 + i;
            [_starView addSubview:imageV];
            [imageV release];
            
        }

        
    }
    

    return self;
}

- (void)getItem:(NSDictionary *)dic bigDic:(NSDictionary *)big
{

    _commentLabel.text = [dic objectForKey:@"content"];
    CGFloat height = [self labelHeight:_commentLabel.text width:[[UIScreen mainScreen]bounds].size.width - 10];
    _commentLabel.frame = CGRectMake(5, 30, [[UIScreen mainScreen] bounds].size.width - 10, height);
    self.timeLabel.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width / 2, _commentLabel.frame.origin.y + _commentLabel.frame.size.height, [[UIScreen mainScreen] bounds].size.width / 2 - 5, 30);
    _nameLabel.text = [dic objectForKey:@"userName"];
    for (NSString *key in dic) {
        
        if ([key isEqualToString:@"releaseDate"]) {
            
            _timeLabel.text = [dic objectForKey:@"releaseDate"];
            for (int i = 0; i < [[dic objectForKey:@"grade"] intValue]; i++) {
                
                UIImageView *imageV = (UIImageView *)[self.contentView viewWithTag:600 + i];
                imageV.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"iconfont-xingxing" ofType:@"png"]];
                
            }
            
            break;
        } else if ([key isEqualToString:@"postdate"]) {
        
            _timeLabel.text = [dic objectForKey:@"postdate"];
            for (int i = 0; i < [[dic objectForKey:@"productGrade"] intValue]; i++) {
                
                UIImageView *imageV = (UIImageView *)[self.contentView viewWithTag:600 + i];
                imageV.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"iconfont-xingxing" ofType:@"png"]];
                
            }
            
            break;
        
        }
        
    }
   
  
   
    
}


- (CGFloat)labelHeight:(NSString *)text width:(CGFloat)width
{

    CGSize size = CGSizeMake(width, 1000);
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14],NSFontAttributeName, nil];
   CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
    

}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
